//mysql query demo 案例
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"

int main(int argc,char *argv[])
{
	int res = 0;
	MYSQL *mysql = mysql_init(NULL);
	
	if(mysql == NULL)
	{
		res = mysql_errno(mysql);
		printf("mysql init error,[%d]",res);
		return -1;
	}
	
	//链接数据库
	////MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd,const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag);
	MYSQL *conn = mysql_real_connect(mysql,"127.0.0.1","root","root","mem",0,NULL,0);
	if(conn == NULL)
	{
		printf("mysql connect is error ,[%s]",mysql_error(conn));
		return -1;
	}

	//做数据库操作
	char sSQL[255] = "insert into account (account,password) values ('sgyt','sgyt')";
	res = mysql_query(conn,sSQL);
	if(res != 0)
	{
		printf("this operation is fail\n");
	}
	printf("mysql_query ok\n");
	mysql_close(conn);
	return 0;
}